<template>
  <div class="main-menu">
    <router-link to="/" class="menu-item">首页</router-link>
    <router-link to="/music-library" class="menu-item">音乐库</router-link>
    <router-link to="/playlists" class="menu-item">播放列表</router-link>
    <div class="user-section">
      <span class="username">{{ currentUser?.username }}</span>
      <button @click="handleLogout" class="logout-btn">退出</button>
    </div>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'

export default {
  name: 'MainMenu',
  setup() {
    const store = useStore()
    const router = useRouter()
    const currentUser = computed(() => store.getters['auth/currentUser'])

    const handleLogout = () => {
      store.dispatch('auth/logout')
      router.push('/login')
    }

    return {
      currentUser,
      handleLogout,
    }
  },
}
</script>

<style scoped>
.main-menu {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.menu-item {
  color: white;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.menu-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.user-section {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.username {
  color: white;
}

.logout-btn {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.logout-btn:hover {
  background-color: #c82333;
}
</style>
